import com.sun.java.swing.plaf.windows.WindowsTextAreaUI;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @author TANGYE
 * @date 2021/1/27 9:52 下午
 **/
public class ViewTwo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        // 去重
        Set set = new HashSet();
        for(int i = 0; i < m; i++){
            set.add(Integer.valueOf(sc.nextInt()));
        }
        int n = sc.nextInt();
        Object[] objects = set.toArray();
        if (n-1 >= objects.length-n){
            System.out.println(-1);
            return;
        }
        Arrays.sort(objects);
        int sum = 0;
        for (int i = 0; i < n; i++){
            sum = sum + (int) objects[i];
        }
        for (int j = objects.length-1; j >= objects.length - n; j--){
            sum = sum + (int) objects[j];
        }
        System.out.println(sum);
    }
}
